// 2025/3/27
// 买卖股票的最好时机1

#include <iostream>
using namespace std;

int main() {
    int n; cin >> n;
    int lowest = 10001, cur = 0, ans = 0;
    while(n--)
    {
        cin >> cur;
        lowest = min(cur, lowest);
        ans = max(ans, cur - lowest);
    }
    cout << ans << endl;
}
// 64 位输出请用 printf("%lld")